Skip to content

grpclb: pick_first delegation#12568

Merged
shivaspeaks merged 6 commits intogrpc:masterfrom
shivaspeaks:port-grpclb
Dec 23, 2025
Merged

grpclb: pick_first delegation#12568
shivaspeaks merged 6 commits intogrpc:masterfrom
shivaspeaks:port-grpclb

Conversation

@shivaspeaks
Copy link
Copy Markdown
Member

Summary of Changes
This pull request refactors the grpclb load balancer's PICK_FIRST mode to delegate its logic to a standard pick_first load balancing policy.

The key changes are as follows:

  1. grpclb/build.gradle

Added dependency on grpc-util module to access ForwardingLoadBalancerHelper

  1. grpclb/src/main/java/io/grpc/grpclb/GrpclbState.java
  • New imports:
    LoadBalancer, LoadBalancerProvider, LoadBalancerRegistry, ResolvedAddresses, FixedResultPicker, ForwardingLoadBalancerHelper
  • New fields for PICK_FIRST delegation:
    • pickFirstLbProvider - Provider for creating child pick_first LB
    • pickFirstLb - The child LoadBalancer instance
    • pickFirstLbState / pickFirstLbPicker - Track child LB's state and picker
    • currentPickFirstLoadRecorder - Load recorder for token attachment
  • Key behavioral changes:
    • updateServerList() PICK_FIRST case: Instead of creating a single subchannel, it now:
      • Creates the child pick_first LB once and then updates it with new addresses on subsequent updates.
      • Passes addresses to child LB via acceptResolvedAddresses()
    • maybeUpdatePicker() PICK_FIRST case: Uses child LB's state and picker wrapped with ChildLbPickerEntry
    • RoundRobinEntry.picked() signature change: Changed from picked(Metadata) to picked(PickSubchannelArgs) to allow child picker delegation
    • New ChildLbPickerEntry class: Wraps child LB's picker and attaches TokenAttachingTracerFactory for token propagation
    • New PickFirstLbHelper class: Forwarding helper that intercepts updateBalancingState() to store child state and trigger grpclb picker updates
    • Updated shutdown(), requestConnection(), maybeUseFallbackBackends(): Handle the new child LB delegation model
  1. grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
  • Updated tests to reflect the new delegation behavior:
    • Initial state is now CONNECTING (not IDLE) since standard pick_first eagerly connects
    • Tests now verify the child LB is created only once and then handles address updates internally.
    • Adjusted verification expectations for the new flow
  • Key Behavioral Changes:
    • Delegation to child LB: The grpclb state no longer directly manages subchannels for PICK_FIRST mode; the child pick_first LB handles this internally.

Copy link
Copy Markdown
Contributor

@kannanjgithub kannanjgithub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review comments.

Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Copy link
Copy Markdown
Contributor

@kannanjgithub kannanjgithub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some deleted code still needs to be restored.

Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java Outdated
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Copy link
Copy Markdown
Contributor

@kannanjgithub kannanjgithub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have a closer look at deleted statements due to trying plain verify which would have failed without inOrder.

Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
@shivaspeaks shivaspeaks marked this pull request as ready for review December 22, 2025 04:59
Comment thread grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
@shivaspeaks shivaspeaks merged commit d0005b2 into grpc:master Dec 23, 2025
17 checks passed
jdcormie pushed a commit to jdcormie/grpc-java that referenced this pull request Feb 11, 2026
**Summary of Changes**
This pull request refactors the grpclb load balancer's PICK_FIRST mode
to delegate its logic to a standard pick_first load balancing policy.

The key changes are as follows:
1. **`grpclb/build.gradle`**

Added dependency on `grpc-util` module to access
`ForwardingLoadBalancerHelper`

2. **`grpclb/src/main/java/io/grpc/grpclb/GrpclbState.java`**
- New imports:
LoadBalancer, LoadBalancerProvider, LoadBalancerRegistry,
ResolvedAddresses, FixedResultPicker, ForwardingLoadBalancerHelper
- New fields for PICK_FIRST delegation:
    - pickFirstLbProvider - Provider for creating child pick_first LB
    - pickFirstLb - The child LoadBalancer instance
- pickFirstLbState / pickFirstLbPicker - Track child LB's state and
picker
    - currentPickFirstLoadRecorder - Load recorder for token attachment
- Key behavioral changes:
- updateServerList() PICK_FIRST case: Instead of creating a single
subchannel, it now:
- Creates the child pick_first LB once and then updates it with new
addresses on subsequent updates.
        - Passes addresses to child LB via acceptResolvedAddresses()
- maybeUpdatePicker() PICK_FIRST case: Uses child LB's state and picker
wrapped with ChildLbPickerEntry
- RoundRobinEntry.picked() signature change: Changed from
picked(Metadata) to picked(PickSubchannelArgs) to allow child picker
delegation
- New ChildLbPickerEntry class: Wraps child LB's picker and attaches
TokenAttachingTracerFactory for token propagation
- New PickFirstLbHelper class: Forwarding helper that intercepts
updateBalancingState() to store child state and trigger grpclb picker
updates
- Updated shutdown(), requestConnection(), maybeUseFallbackBackends():
Handle the new child LB delegation model

3. **`grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java`**

- Updated tests to reflect the new delegation behavior:
- Initial state is now CONNECTING (not IDLE) since standard pick_first
eagerly connects
- Tests now verify the child LB is created only once and then handles
address updates internally.
    - Adjusted verification expectations for the new flow
- Key Behavioral Changes:
- Delegation to child LB: The grpclb state no longer directly manages
subchannels for PICK_FIRST mode; the child pick_first LB handles this
internally.
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants